<template>
  <a-card :bordered="false" class="card-area">
    <a-tabs defaultActiveKey="1">
      <a-tab-pane tab="学生信息" key="1">
        <stu-info ref="stuInfo" :info="info" />
      </a-tab-pane>
      <a-tab-pane tab="导师信息" key="2" forceRender>
        <stu-status-info v-if="info.xh" ref="stuStatusInfo" :xjxx="xjxx" />
      </a-tab-pane>
      <!-- <a-tab-pane tab="学籍信息" key="2" forceRender>
        <stu-status-info v-if="info.xh" ref="stuStatusInfo" :xjxx="xjxx" />
      </a-tab-pane>
      <a-tab-pane tab="个人简历" key="3" forceRender>
        <stu-resume v-if="info.xh" ref="stuResume" :info="info"/>
      </a-tab-pane>
      <a-tab-pane tab="社会关系" key="4" forceRender>
        <stu-relation v-if="info.xh" ref="stuRelation" :info="info"/>
      </a-tab-pane> -->
    </a-tabs>
    <div class="ant-pro-footer-toolbar">
      <div style="float: right; margin-top: 10px;">
        <a-button style="margin-right: 10px;" @click="back">返回列表</a-button>
        <a-button style="margin-right: 10px;" :loading="loading" @click="saveStu" type="primary">保存</a-button>
      </div>
    </div>
    <!-- <a-row style="text-align:center">
      <a-button @click="saveStu" type="primary">保存</a-button>
    </a-row> -->
  </a-card>
</template>
<script>
// import { mapState } from 'vuex'
import stuInfo from '../../stuStatus/search/component/stuInfo'
// import stuStatusInfo from '../../stuStatus/search/component/stuStatusInfo'
// import stuRelation from './components/stuRelation'
// import stuResume from './components/stuResume'
import stuStatusInfo from '../../stuStatus/search/component/stuStatusInfo'

export default {
  data () {
    return {
      info: {},
      xjxx:{},
      loading: false
    }
  },
  components: {
    stuInfo,
    // stuRelation,
    // stuStatusInfo,
    // stuResume,
    stuStatusInfo
  },
  computed: {
    xh () {
      return this.$route.query.xh
    }
  },
  beforeCreate () {
    // this.form = this.$form.createForm(this)
  },
  created () {
    this.$api.overseas.stuInfo(this.xh).then(res => {
      this.info = Object.assign(res.data,res.data.xjxx)
      this.xjxx = this.info.xjxx
      console.log(this.xjxx)
      this.xjxx.jzgXmDetail = res.data.jzgXmDetail
      this.$changeDate(this.xjxx)
      this.$changeDate(this.info)
      // this.$nextTick(() => {
      //   this.form.setFieldsValue(res.data)
      // })
    })
  },
  methods: {
    saveStu () {
      let isComplete = true
      this.$refs.stuInfo.form.validateFields((err, values) => {
        this.$refs.stuInfo.$refs.stuInfo1.form.validateFields((err1) => {
          if (err1) {
            isComplete = false
            this.$message.error('请输入学生信息必填项')
            return
          }
        })
        if (err) {
          isComplete = false
          this.$message.error('请输入学生信息必填项')
          return
        }
      })
      this.$refs.stuStatusInfo.form.validateFields((err, values) => {
        if (err) {
          isComplete = false
          this.$message.error('请输入学籍信息必填项')
          return
        }
      })
      if(!isComplete){
        return;
      }
      this.loading = true
      const data = Object.assign(
        this.$refs.stuInfo.form.getFieldsValue(),
        this.$refs.stuInfo.$refs.stuInfo1.form.getFieldsValue(),
      )
      const xjxx = this.$refs.stuStatusInfo && this.$refs.stuStatusInfo.form.getFieldsValue()
        this.$DateToString(data)
        // this.$DateToString(rxcj)
        this.$DateToString(xjxx)
        // data.rxcj = rxcj
        data.xjxx = xjxx
        data.xjxx.ssyxm = data.ssyxm
        data.xjxx.sszym = data.sszym
        data.xjxx.hwzz = data.hwzz
        data.xjxx.lxgbm = data.lxgbm
        data.xjxx.lxgxyx = data.lxgxyx
        data.xjxx.lxxxqx = data.lxxxqx
        data.xjxx.nbysj = data.nbysj
        data.xjxx.sznj = data.sznj
        data.xjxx.rxny = data.rxny
        data.xjxx.xnzsdz = data.xnzsdz

        
        data.teacherIds = this.$refs.stuStatusInfo.gndsData.map(item=>item.id)
        data.projectIds = this.$refs.stuStatusInfo.gndsData.map(item=>item.xmId)
      this.$api.overseas.studentUpdate(data).then(res => {
        this.$message.success(res.msg)
        // this.$router.push('/student/stuStatus/search')
        // this.$refs.stuInfo.form.resetFields()
        // this.$refs.score.form.resetFields()
        // this.$refs.stuStatusInfo.form.resetFields()
      }).finally(() => {
        this.loading = false
      })
    },
    back () {
      // this.$emit('showList')
      this.$router.back()
    }
  }
}
</script>

<style lang="less" scoped>

</style>
